import request from "@/utils/axios";

// 封禁类型枚举
export enum BlockType {
  ACCOUNT = 1, // 账号封禁
  DEVICE = 2, // 设备封禁
  IP = 3, // IP封禁
  LOGIN_LIMIT = 4, // 限制登录类型
}

// 封禁类型文本映射
export const BlockTypeText = {
  [BlockType.ACCOUNT]: "账号封禁",
  [BlockType.DEVICE]: "设备封禁",
  [BlockType.IP]: "IP封禁",
  [BlockType.LOGIN_LIMIT]: "限制登录类型",
} as const;

// 封禁类型样式映射
export const BlockTypeType = {
  [BlockType.ACCOUNT]: "danger",
  [BlockType.DEVICE]: "warning",
  [BlockType.IP]: "info",
  [BlockType.LOGIN_LIMIT]: "warning",
} as const;

// 封禁原因分类映射
export const ReasonCategoryText = {
  porn: "色情内容",
  violence: "暴力内容",
  spam: "垃圾信息",
  fraud: "诈骗行为",
  other: "其他违规",
} as const;

// 封禁状态枚举
export enum BlockStatus {
  YES = 1, // 是
  NO = 2, // 否
}

// 封禁状态文本映射
export const BlockStatusText = {
  [BlockStatus.YES]: "是",
  [BlockStatus.NO]: "否",
} as const;

// 封禁状态样式映射
export const BlockStatusType = {
  [BlockStatus.YES]: "danger",
  [BlockStatus.NO]: "info",
} as const;

// 搜索请求参数
export interface BlockSearchReq {
  content?: string; // 内容（包含设备、ip）
  type?: number; // 类型 1账号封禁 2设备封禁 3IP封禁 4限制登录类型
  startTime?: string; // 开始时间（UTC+0格式）
  endTime?: string; // 结束时间（UTC+0格式）
  pageIndex: number; // 页码
  pageSize: number; // 每页大小
}

// 封禁记录数据
export interface BlockRecordDto {
  id: string;
  createUser: string | null;
  createTime: string;
  modifyUser: string | null;
  modifyTime: string;
  userId: string;
  userNo: string;
  nickname: string;
  avatar: string;
  countryCode: string;
  content: string;
  type: number;
  operatorUserId: string;
  startTime: string;
  endTime: string;
  reasonCategory: string;
  remark: string | null;
  status: number;
}

// 分页响应数据
export interface BlockPageRes {
  hasNextPage: boolean;
  list: BlockRecordDto[];
  nextPage: number;
  count: number;
  total: number;
  size: number;
}

// 封禁类型响应数据
export interface BlockTypesRes {
  [key: string]: string;
}

// 封禁原因分类数据
export interface BlockCategoryItem {
  zh: string;
  en: string;
  ar: string;
  text: string;
}

// 封禁原因响应数据
export interface BlockCategoriesRes {
  [key: string]: BlockCategoryItem;
}

// 添加封禁请求参数
export interface BlockAddReq {
  userId: string; // 用户Id
  content: string; // 封禁uid传uid，封禁设备传设备号，封禁ip传ip
  type?: number; // 封禁类型
  reasonCategory: string; // 封禁原因，porn,harassment 请参考 ViolationCategoryEnum
  remark?: string; // 备注
  durationOfSeconds: number; // 封禁的时长（秒）
}

// API接口定义
const Api = {
  BlockPage: "/block/page",
  BlockTypes: "/block/types",
  BlockCategories: "/block/categories",
  BlockAdd: "/block",
  BlockAddAvatar: "/user/avatar/reset",
  BlockRemove: "/block",
} as const;

// 获取封禁记录分页列表
export const getBlockPageApi = (data: BlockSearchReq) => {
  return request.post<BlockPageRes>(Api.BlockPage, data);
};

// 获取封禁类型列表
export const getBlockTypesApi = () => {
  return request.get<BlockTypesRes>(Api.BlockTypes);
};

// 获取封禁原因分类列表
export const getBlockCategoriesApi = () => {
  return request.get<BlockCategoriesRes>(Api.BlockCategories);
};

// 添加封禁
export const addBlockApi = (data: BlockAddReq) => {
  return request.post(Api.BlockAdd, data);
};

// 解除封禁
export const unBlockApi = (blockId: string) => {
  return request.post(`${Api.BlockRemove}/${blockId}/remove`);
};

// 重置用户头像
export const resetUserAvatarApi = (userId) => {
  return request.post(Api.BlockAddAvatar, null, { params: { userId } });
};
